from odoo import api, fields, models


class SubcontractProductSupplierinfo(models.Model):
    _name = 'subcontract.product.supplierinfo'
    _description = '分包供应商价格表'

    partner_id = fields.Many2one('res.partner', string='供应商')
    delay = fields.Integer(string='交货提前时间')
    product_temp_id = fields.Many2one('product.template', '产品', domain=[('detailed_type', '!=', 'service')])
    service_product = fields.Many2one('product.template', string='服务', domain=[('detailed_type', '=', 'service')])
    pcs_price = fields.Float(string='Pcs价')
    panel_price = fields.Float(string='Panel价')
    set_price = fields.Float(string='Set价')

    @api.onchange('pcs_price')
    def onchange_price1(self):
        # 1pan = 2set = 4pcs
        if self.pcs_price:
            self.set_price = self.pcs_price / 2
            self.panel_price = self.pcs_price / 4
        else:
            self.panel_price = 0
            self.pcs_price = 0
            self.set_price = 0

    @api.onchange('panel_price')
    def onchange_price2(self):
        # 1pan = 2set = 4pcs
        if self.panel_price:
            self.set_price = 2 * self.panel_price
            self.pcs_price = 4 * self.panel_price
        else:
            self.panel_price = 0
            self.pcs_price = 0
            self.set_price = 0

    @api.onchange('set_price')
    def onchange_price3(self):
        # 1pan = 2set = 4pcs
        if self.set_price:
            self.panel_price = self.set_price / 2
            self.pcs_price = 2 * self.set_price
        else:
            self.panel_price = 0
            self.pcs_price = 0
            self.set_price = 0
